package com.cms.cmsbackend.service;

import com.cms.cmsbackend.mapper.LinkMapper;
import com.cms.cmsbackend.pojo.Link;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LinkService {
    @Autowired
    private LinkMapper linkMapper;

    public void save(Link link ){
       linkMapper.insert(link);

    }

    public PageInfo findByPage(int size,int page){
        //开始分页
        PageHelper.startPage(page,size);
        //查询指定页码的数据
        List<Link> links=linkMapper.selectAll();
        //将数据封装成一个PageInfo对象
        PageInfo pageInfo=new PageInfo<>(links);
        return pageInfo;
    }

    public void delete(int id){
        linkMapper.deleteByPrimaryKey(id);
    }

    public Link updatalink(Link link){
        linkMapper.updateByPrimaryKey(link);
        return link;
    }

    public void batchdel(int[] ids){
        for(int id:ids){
            linkMapper.deleteByPrimaryKey(id);
        }
    }

    public Link findById(int id){
        Link link=linkMapper.selectByPrimaryKey(id);
        return link;
    }
}
